﻿using System;
using System.ServiceModel;
using System.Runtime.Serialization;
using System.Collections;
using System.Collections.Generic;
using System.Net.NetworkInformation;
using System.Net;

namespace Server {
	[DataContract(Namespace = "Client")]
	public enum WifiSecurityType {
		[EnumMember]
		Open,
		[EnumMember]
		WEP,
		[EnumMember]
		WPA_PSK,
		[EnumMember]
		WPA2_PSK
	}

	[DataContract(Namespace = "Client")]
	public enum WifiEncryptionType {
		[EnumMember]
		none,
		[EnumMember]
		TKIP,
		[EnumMember]
		AES,
		[EnumMember]
		WEP
	}

	[DataContract(Namespace = "Client")]
	public class TestResult {
		[DataMember]
		public String Name {
			get;
			set;
		}

		[DataMember]
		public Guid Node {
			get;
			set;
		}

		[DataMember]
		public String Description {
			get;
			set;
		}

		[DataMember]
		public String ResultsHeader {
			get;
			set;
		}

		[DataMember]
		public Guid Id {
			get;
			set;
		}

		[DataMember]
		public DateTime StartTime {
			get;
			set;
		}

		[DataMember]
		public DateTime EndTime {
			get;
			set;
		}
		/// <summary>
		/// (Status, [RoundtripTime in ms])
		/// </summary>
		[DataMember]
		public List<String> Results {
			get;
			set;
		}
	}

	[DataContract(Namespace = "Client")]
	public struct WifiConnectionState {
		[DataMember]
		public long ConnectionIPv4StatisticsBytesReceived {
			get;
			set;
		}
		[DataMember]
		public String ConnectionSSID {
			get;
			set;
		}
		[DataMember]
		public long ConnectionIPv4StatisticsBytesSent {
			get;
			set;
		}
		[DataMember]
		public long ConnectionIPv4StatisticsUnicastPacketsSent {
			get;
			set;
		}
		[DataMember]
		public long ConnectionIPv4StatisticsUnicastPacketsReceived {
			get;
			set;
		}
		[DataMember]
		public long ConnectionIPv4StatisticsOutputQueueLength {
			get;
			set;
		}
		[DataMember]
		public long ConnectionIPv4StatisticsIncomingPacketsDiscarded {
			get;
			set;
		}
		[DataMember]
		public long ConnectionIPv4StatisticsIncomingPacketsWithErrors {
			get;
			set;
		}
		[DataMember]
		public long ConnectionIPv4StatisticsIncomingUnknownProtocolPackets {
			get;
			set;
		}
		[DataMember]
		public long ConnectionIPv4StatisticsOutgoingPacketsDiscarded {
			get;
			set;
		}
		[DataMember]
		public long ConnectionIPv4StatisticsOutgoingPacketsWithErrors {
			get;
			set;
		}
		[DataMember]
		public byte[] ConnectionIPv4UnicastAddress {
			get;
			set;
		}
		[DataMember]
		public byte[] ConnectionIPv4UnicastMask {
			get;
			set;
		}
		[DataMember]
		public byte[] ConnectionIPv4GatewayAddress {
			get;
			set;
		}
		[DataMember]
		public String InterfacePhysicalAddress {
			get;
			set;
		}
		[DataMember]
		public String ConnectionOperationalStatus {
			get;
			set;
		}
		[DataMember]
		public long ConnectionSpeed {
			get;
			set;
		}
		[DataMember]
		public int ConnectionRSSI {
			get;
			set;
		}
		[DataMember]
		public String InterfaceState {
			get;
			set;
		}
		[DataMember]
		public String ConnectionProfileName {
			get;
			set;
		}
		[DataMember]
		public int Channel {
			get;
			set;
		}
		[DataMember]
		public String BssType {
			get;
			set;
		}
		[DataMember]
		public String InterfaceName {
			get;
			set;
		}
	}

	public interface IServiceModelServerCallback {
		[OperationContract(Name = "ResponseTestConnection")]
		Boolean TestConnection();

		[OperationContract]
		WifiConnectionState WifiGetConnectionState();

		[OperationContract]
		Boolean WifiConnect(String ssid, WifiSecurityType securityType, WifiEncryptionType encryptionType, String securityKey);

		[OperationContract]
		Boolean WifiDisconnect();

		//[OperationContract]
		//void WifiScan();
		[OperationContract]
		void Shutdown();

		[OperationContract]
		Guid TestPing(String testName, String host, int count, int interval, int timeout, bool async);

		[OperationContract]
		void StartCustomTestServer(String command, int timeout);

		[OperationContract]
		void StopCustomTestServer();

		[OperationContract]
		Guid TestCustomTest(String testName, String command, int timeout);

		//[OperationContract]
		//void GetNodeInfo();

		[OperationContract]
		Dictionary<Guid, TestResult> GetTestResults();

		[OperationContract]
		TestResult GetTestResult(Guid guid);

		[OperationContract]
		Boolean ContainsResult(Guid guid);

		[OperationContract]
		Guid[] GetTestResultList();

		[OperationContract]
		String[] GetLogs();

		[OperationContract(Name = "GetLogsLastLines")]
		String[] GetLogs(int index);
	}
}
